import "package:ct_pa_majordomo/config/theme_vars.dart";
import "package:ct_pa_majordomo/pages/device/electricity_meter/api.dart";
import "package:ct_pa_majordomo/pages/device/electricity_meter/use_record/widgets/tab_layout.dart";
import "package:flutter/material.dart";

class UseRecord extends StatefulWidget {
  final int id;
  const UseRecord({super.key, required this.id});

  @override
  State<StatefulWidget> createState() => _UseRecordState();

}

class _UseRecordState extends State<UseRecord> {

  void _useRecord() async {
    Map<String, dynamic> params = {
      "electricityMeterId": widget.id,
      "startDate": "2024-01-01",
      "endDate": "2024-12-31",
    };
    Map resData = await electricityMeterApi.useRecord(params);
    List list = resData["rows"] ?? [];
    print("buyingg:>>>>>>>>>>$list");
  }

  @override
  void initState() {
    // _useRecord();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: 3,
      child: Scaffold(
        appBar: AppBar(
          iconTheme: const IconThemeData(color: Colors.white),
          title: const Text("用电记录", style: TextStyle(color: Colors.white),),
          centerTitle: true,
          backgroundColor: ThemeVars.colorPrimary,
          leading: IconButton(
            icon: const Icon(Icons.arrow_back_ios_new),
            onPressed: () {
              Navigator.pop(context);
            },
          ),
          bottomOpacity: 1,
          bottom: const PreferredSize(
              preferredSize: Size.fromHeight(48),
              child: Material(
                color: Colors.white,
                child: TabBar(
                  tabs: [Tab(text: "年",), Tab(text: "月",), Tab(text: "日",)],
                ),
              )
          ),
        ),
        body: TabBarView(
          children: [
            TabLayout(type: TabType.year, id: widget.id,),
            TabLayout(type: TabType.month, id: widget.id,),
            TabLayout(type: TabType.date, id: widget.id,),
          ],
        ),
      ),
    );
  }

}